package ca.ioniq.shared.entity;

// Generated Jan 20, 2011 9:08:49 AM by Hibernate Tools 3.4.0.Beta1

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Order generated by hbm2java
 */
@Entity
@Table(name = "orders")
@XmlRootElement(name = "order")
public class Order implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Long id;
	private User user;
	private Date datePlaced;
	private Byte status;
	private Long totalPrice;
	private Company company;
	private Set<Item> items = new HashSet<Item>(0);

	public Order() {
	}

	public Order(User user, Date datePlaced, Byte status,
			Set<Item> items) {
		this.user = user;
		this.datePlaced = datePlaced;
		this.status = status;
		this.items = items;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	@XmlElement
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "user_id")
	@XmlElement
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_placed", length = 19)
	@XmlElement
	public Date getDatePlaced() {
		return this.datePlaced;
	}

	public void setDatePlaced(Date datePlaced) {
		this.datePlaced = datePlaced;
	}

	@Column(name = "status")
	@XmlElement
	public Byte getStatus() {
		return this.status;
	}

	public void setStatus(Byte status) {
		this.status = status;
	}

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name="order_has_items", 
      joinColumns=@JoinColumn(name="item_id"),
      inverseJoinColumns=@JoinColumn(name="order_id")) 
	@XmlElement
    public Set<Item> getItems() {
		return items;
	}

	public void setItems(Set<Item> items) {
		this.items = items;
	}

	@Column(name = "total_price")
	public Long getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(Long totalPrice) {
		this.totalPrice = totalPrice;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "company_id")
	@XmlElement
	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

}
